﻿using DevTeam;
using System.Collections.Generic;
using System.Data;

namespace ConfExpert.Forms.ImportWizards
{
    public partial class Albini_Tip1 : XITopCekiListesi
    {
        int YuklemeId;
        public Albini_Tip1(int YuklemeId) :
            base(YuklemeId)
        {
            InitializeComponent();

            this.YuklemeId = YuklemeId;
            Init("Albini Tip1 Çeki Listesi", true);
            this.FileDone += MontiTip1_FileDone;
        }

        void MontiTip1_FileDone(DataSet ds, string FileName)
        {
            DataTable dt = ds.Tables[0];
            DataRowCollection rows = dt.Rows;
            DataColumnCollection cols = dt.Columns;
        
            Dictionary<string, int> indexes = new Dictionary<string, int>();
            for  ( int colIndex = 0; colIndex < dt.Columns.Count ; colIndex++)
            {
                DataRow dr0 = dt.Rows[0];
                string colName = dr0[colIndex].ToStr();
                switch (colName)
                {
                    case "Artikel": indexes.Add("Article", colIndex); break;
                    case "VendorRollId": indexes.Add("VendorRollId", colIndex); break;
                    case "Qty": indexes.Add("Qty", colIndex); break;
                    case "Width": indexes.Add("Width", colIndex); break;                    
                }                    
            }
            
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                DataRow dr = rows[i];
                string article = dr[indexes["Article"]].ToStr();
                if (Article.Select("Article='" +  article + "'").Length == 0)
                {
                    DataRow drArticle = Article.NewRow();
                    drArticle["Article"] = article;                    
                    Article.Rows.Add(drArticle);
                }
                DataRow drRoll = Roll.NewRow();
                drRoll["Article"] = article;
                
                drRoll["VendorRollId"] = dr[indexes["VendorRollId"]];
                drRoll["Qty"] = dr[indexes["Qty"]];
                drRoll["WidthUsable"] = dr[indexes["Width"]];
                
                Roll.Rows.Add(drRoll);
            }
        }
       
        
    }
}


